package com.egan.pet.config;

import com.egan.pet.admin.utils.LoginInterceptor;
import com.egan.pet.admin.utils.RefreshTokenInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @author NoobMaster69  * @date 2024/6/29 0029 星期六 9:33
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //1.拦截部分 order()值越高，执行越晚
        registry.addInterceptor(new LoginInterceptor()).excludePathPatterns(
                "/v3/api-docs",
                "/v3/api-docs/**",
                "/swagger-resources/**",
                "/webjars/**",
                "/doc.html/**",
                "/user/login",
                "/user/loginToPass",
                "/user/code").order(1);
        //2.拦截全部
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate))
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/v3/api-docs",
                        "/v3/api-docs/**",
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/doc.html/**",
                        "/user/login",
                        "/user/loginToPass",
                        "/user/code")
                .order(0);
    }
}
